package com.ebelter.nb.ui.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.nb.R;


/**
 * Created by ZCQ on 2017/12/1
 * 组合控件6 不知道怎么起名字了 还是按序号来吧
 */

public class CombinView6 extends LinearLayout{
    public CombinView6(Context context) {
        this(context,null);
    }




    public CombinView6(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }




    public CombinView6(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CombinView6);
        if (typedArray != null) {
            title1 = typedArray.getString(R.styleable.CombinView6_title1);
            title2 = typedArray.getString(R.styleable.CombinView6_title2);
            drawable = typedArray.getDrawable(R.styleable.CombinView6_image1);
            isDisplayLine = typedArray.getBoolean(R.styleable.CombinView6_isDisplayLine,true);
            typedArray.recycle();
        }

        initView(getContext());


    }

    private String title1;
    private String title2;
    private boolean isDisplayLine;
    private Drawable drawable;




    private TextView title1_tv;
    private RelativeLayout rl;
    private TextView title2_tv;
    private ImageView image1_iv;

    private View cb6_lineView;



    private void initView(Context context) {
        View view =  View.inflate(context, R.layout.cb6_layout, this);//把那个布局当做是自己的孩子

        title1_tv = view.findViewById(R.id.cb6_title1_tv);
        rl = view.findViewById(R.id.cb6_rl);
        title2_tv = view.findViewById(R.id.cb6_title2_tv);
        image1_iv = view.findViewById(R.id.cb6_image1_iv);
        cb6_lineView = view.findViewById(R.id.cb6_lineView);

        setTitle1(title1);
        setTitle2(title2);
        if (!isDisplayLine){
            ViewUtils.goneView(cb6_lineView);
        }
        image1_iv.setImageDrawable(drawable);


    }


    public void setWeight(int left,int right){
        ViewUtils.setWeight(title1_tv,left);
        ViewUtils.setWeight(rl,right);
    }






    public void setTitle1(String title1){
        this.title1=title1;
        if (title1_tv!=null){
            title1_tv.setText(this.title1);
        }
    }
    public void setTitle2(String title2){
        this.title2=title2;
        if (title2_tv!=null){
            title2_tv.setText(this.title2);
        }
    }
    public void setImage1(int res){
        if (image1_iv!=null){
            image1_iv.setImageResource(res);
        }
    }

}
